consolidate custom parameter parsing routines looking for boolean values
authorKeir Fraser <keir@xen.org>
Fri, 19 Nov 2010 13:25:54 +0000 (13:25 +0000)
committerKeir Fraser <keir@xen.org>
Fri, 19 Nov 2010 13:25:54 +0000 (13:25 +0000)
Have a single function for this, rather than doing the same in half a
dozen places.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
xen/arch/x86/cpu/amd.c
xen/arch/x86/setup.c
xen/arch/x86/x86_64/mmconfig-shared.c
xen/common/kernel.c
xen/drivers/passthrough/iommu.c
xen/drivers/passthrough/vtd/x86/ats.c
xen/include/xen/lib.h

index 591a566f578c97ed9c338b0529d4da9dcd93dcda..2fb25c0e70b7466af32feaafa92bc550afe64ebc 100644 (file)
@@ -240,13 +240,18 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw, ...)
  * amd_flush_filter={on,off}. Forcibly Enable or disable the TLB flush
  * filter on AMD 64-bit processors.
  */
-static int flush_filter_force;
-static void flush_filter(char *s)
+static int __read_mostly flush_filter_force;
+static void __init flush_filter(char *s)
 {
-       if (!strcmp(s, "off"))
+       switch (parse_bool(s))
+       {
+       case 0:
                flush_filter_force = -1;
-       if (!strcmp(s, "on"))
+               break;
+       case 1:
                flush_filter_force = 1;
+               break;
+       }
 }
 custom_param("amd_flush_filter", flush_filter);
 
index 862900ed88d663894f21d061bf1e8d85b1b56971..42e063aa79b438b61f61911e0d4b50ae777c5b93 100644 (file)
@@ -113,7 +113,7 @@ static void __init parse_acpi_param(char *s)
     safe_strcpy(acpi_param, s);
 
     /* Interpret the parameter for use within Xen. */
-    if ( !strcmp(s, "off") )
+    if ( !parse_bool(s) )
     {
         disable_acpi();
     }
index abc851757f47c63fad3b6f71f83a998ff2579abd..f1d790ec9e90cde44560af8a26e5114d2cd0bc8d 100644 (file)
@@ -37,8 +37,7 @@ static void __init parse_mmcfg(char *s)
         if ( ss )
             *ss = '\0';
 
-        if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") ||
-             !strcmp(s, "0") || !strcmp(s, "disable") )
+        if ( !parse_bool(s) )
             pci_probe &= ~PCI_PROBE_MMCONF;
         else if ( !strcmp(s, "amd_fam10") || !strcmp(s, "amd-fam10") )
             pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
index 96a55318f2baa9b497ac2e6f7121040bb4e51c13..0bc954c1aa0d8a193657e589e4112786e558745a 100644 (file)
@@ -26,7 +26,7 @@ int tainted;
 
 xen_commandline_t saved_cmdline;
 
-void cmdline_parse(char *cmdline)
+void __init cmdline_parse(char *cmdline)
 {
     char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
@@ -83,10 +83,7 @@ void cmdline_parse(char *cmdline)
                 break;
             case OPT_BOOL:
             case OPT_INVBOOL:
-                if ( !strcmp("no", optval) ||
-                     !strcmp("off", optval) ||
-                     !strcmp("false", optval) ||
-                     !strcmp("0", optval) )
+                if ( !parse_bool(optval) )
                     bool_assert = !bool_assert;
                 if ( param->type == OPT_INVBOOL )
                     bool_assert = !bool_assert;
@@ -115,6 +112,25 @@ void cmdline_parse(char *cmdline)
     }
 }
 
+int __init parse_bool(const char *s)
+{
+    if ( !strcmp("no", s) ||
+         !strcmp("off", s) ||
+         !strcmp("false", s) ||
+         !strcmp("disable", s) ||
+         !strcmp("0", s) )
+        return 0;
+
+    if ( !strcmp("yes", s) ||
+         !strcmp("on", s) ||
+         !strcmp("true", s) ||
+         !strcmp("enable", s) ||
+         !strcmp("1", s) )
+        return 1;
+
+    return -1;
+}
+
 /**
  *      print_tainted - return a string to represent the kernel taint state.
  *
index 57f0daa3761a32fcd9f165df08e3cfa4d4375f41..65c672a1e108a226c2ff2fb94a43b1f8f2a08395 100644 (file)
@@ -59,8 +59,7 @@ static void __init parse_iommu_param(char *s)
         if ( ss )
             *ss = '\0';
 
-        if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") ||
-             !strcmp(s, "0") || !strcmp(s, "disable") )
+        if ( !parse_bool(s) )
             iommu_enabled = 0;
         else if ( !strcmp(s, "force") || !strcmp(s, "required") )
             force_iommu = 1;
index cf564444cd6e65260fb8539c3f74cb8d0d606010..1f8efff6bc298828a8c2fc24194c7c0d8c0e7f57 100644 (file)
@@ -58,13 +58,15 @@ static void __init parse_ats_param(char *s)
         if ( ss )
             *ss = '\0';
 
-        if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") ||
-             !strcmp(s, "0") || !strcmp(s, "disable") )
+        switch ( parse_bool(s) )
+        {
+        case 0:
             ats_enabled = 0;
-
-        if ( !strcmp(s, "on") || !strcmp(s, "yes") || !strcmp(s, "true") ||
-             !strcmp(s, "1") || !strcmp(s, "enable") )
+            break;
+        case 1:
             ats_enabled = 1;
+            break;
+        }
 
         s = ss + 1;
     } while ( ss );
index e09929a604d798cf1bc8bd1213db71980963cf9e..7e25cb5a2966bb242b46d2c1927558645b4605cf 100644 (file)
@@ -57,6 +57,7 @@ do {                                                            \
 struct domain;
 
 void cmdline_parse(char *cmdline);
+int parse_bool(const char *s);
 
 /*#define DEBUG_TRACE_DUMP*/
 #ifdef DEBUG_TRACE_DUMP